{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load  sizeformat %}
{% load  tz %}

{% block head %}
    <link rel="stylesheet" type="text/css" href="{% static 'vms/vms_list.css' %}">
{% endblock %}
{% block title %}{% translate '虚拟机归档列表' %}{% endblock %}

{% block boby %}
        <div class="container-fluid">
        <div class="card">
{#            <div class="card-header">#}
{#                <span class="card-title"><strong><a href="{% url 'log-record:log-record-list' %}"#}
{#                                                    class="btn btn-outline-primary active">{% translate '用户操作日志' %} ({{ count }})</a></strong></span>#}
{#                <span class="card-title"><strong><a href="{% url 'reports:reports-list' %}"#}
{#                                                    class="btn btn-outline-primary">{% translate '资源统计管理' %}</a></strong></span>#}
{#            </div>#}
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <form class="input-group">
                            <input class="form-control" name="search" type="text" value="{{ search }}"
                                   placeholder="UUID、IP地址、用户名">
                            <button class="btn btn-sm btn-outline-primary" type="submit">{% translate '搜索' %}</button>
                        </form>
                    </div>
                </div>
            </div>
            <table class="table table-hover text-center table-vm-list"
                   style="word-wrap:break-word;word-break:break-all;">
                <thead class="thead-light">
                <tr>
                    <th>{% translate '序号' %}</th>
                    <th>{% translate '虚拟机UUID' %}</th>
                    <th>{% translate 'IP地址' %}</th>
                    <th>{% translate 'CPU数' %}</th>
                    <th>{% translate '内存' %}</th>
                    <th>{% translate '可恢复' %}</th>
                    <th>{% translate '归档类型' %}</th>
                    <th>{% translate '系统盘类型' %}</th>
                    <th>{% translate '系统盘名称' %}</th>
                    <th>{% translate '系统盘大小' %}</th>
                    <th>{% translate '用户' %}</th>
                    <th>{% translate '日期' %}</th>
                    {% if request.user.is_superuser %}
                    <th>{% translate '操作' %}</th>
                    {% endif %}
                </tr>
                </thead>
                <tbody>
                {% for obj in vm_recover_list %}
                    <tr>
                        <td>{{ forloop.counter }}</td>
                        <td>{{ obj.uuid }}</td>
                        <td>{{ obj.ipv4 }}</td>
                        <td>{{ obj.vcpu }}</td>
                        <td>{{ obj.mem }}</td>
                        <td>
                            {% if obj.is_recover is True %}
                                <i class="far fa-check-circle" style="color: green"/>
                            {% else %}
                                <i class="far fa-times-circle" style="color: red"/>
                            {% endif %}
                        </td>
                        <td>{{ obj.get_archive_type_display }}</td>
                        <td>{{ obj.disk_type }}</td>
                        <td>{{ obj.disk }}</td>
                        <td>{{ obj.sys_disk_size }}</td>
                        <td>{{ obj.user }}</td>
                        {% timezone request.session.useTimeZone|default:'UTC' %}
                        <td>{{ obj.archive_time|date:'Y-m-d H:i:s' }}</td>
                        {% endtimezone %}
                        {% if request.user.is_superuser %}
                        <td style="width: 150px">
                            {% if obj.is_recover is True %}
                                <a class="btn btn-sm btn-success" id="vm-archive-recover" style="color: white"
                                   data-vm-archive-id="{{ obj.uuid }}" onclick="vm_archive_recover('{{ obj.uuid }}', false, '{{ obj.id }}')">{% translate '恢复' %}</a>
                                <a class="btn btn-sm btn-danger" id="vm-archive-recover-xml"
                                   style="color: white" data-vm-archive-id="{{ obj.uuid }}" onclick="vm_archive_recover('{{ obj.uuid }}', true, '{{ obj.id }}')">{% translate 'xml重构恢复' %}</a>
                            {% endif %}
                        </td>
                        {% endif %}
                    </tr>
                {% endfor %}
            </table>
            {% with page_list=page_nav.page_list previous=page_nav.previous next=page_nav.next %}
                {% if page_list %}
                    <div class="card-footer">
                        <nav aria-label="Page navigation">
                            <ul class="pagination" style="margin:0;">
                                {% if previous %}
                                    <li class="page-item"><a class="page-link" href="?{{ previous }}"
                                                             aria-label="Previous"><span
                                            aria-hidden="true">&laquo;</span></a></li>
                                {% else %}
                                    <li class="page-item disable"><span class="page-link"
                                                                        aria-hidden="true">&laquo;</span></li>
                                {% endif %}
                                {% for disp, query, active in page_list %}
                                    {% if active %}
                                        <li class="page-item active"><a class="page-link"
                                                                        href="?{{ query }}">{{ disp }}</a></li>
                                    {% else %}
                                        <li class="page-item"><a class="page-link" href="?{{ query }}">{{ disp }}</a>
                                        </li>
                                    {% endif %}
                                {% endfor %}
                                {% if next %}
                                    <li class="page-item"><a class="page-link" href="?{{ next }}"
                                                             aria-label="Next"><span
                                            aria-hidden="true">&raquo;</span></a></li>
                                {% else %}
                                    <li class="page-item disable"><span class="page-link"
                                                                        aria-hidden="true">&raquo;</span></li>
                                {% endif %}
                            </ul>
                        </nav>
                    </div>
                {% endif %}
            {% endwith %}
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="{% static 'evcloud/common.js' %}"></script>
    <script type="text/javascript" src="{% static 'vms/vms_archive_recover.js' %}"></script>
{% endblock %}

